﻿using Kenly.DBFramework.Gateway;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using Kenly.DBFramework;

using Kenly.DBFramework.TestModel.Purchasing;

namespace Kenly.DBFramework.Tests
{
    
    
    /// <summary>
    ///这是 GatewayConfigTest 的测试类，旨在
    ///包含所有 GatewayConfigTest 单元测试
    ///</summary>
    [TestClass()]
    public class GatewayConfigTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///获取或设置测试上下文，上下文提供
        ///有关当前测试运行及其功能的信息。
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region 附加测试属性
        // 
        //编写测试时，还可使用以下属性:
        //
        //使用 ClassInitialize 在运行类中的第一个测试前先运行代码
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //使用 ClassCleanup 在运行完类中的所有测试后再运行代码
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //使用 TestInitialize 在运行每个测试前先运行代码
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //使用 TestCleanup 在运行完每个测试后运行代码
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///GatewayConfig 构造函数 的测试
        ///</summary>
        [TestMethod()]
        public void GatewayConfigConstructorTest()
        {
            GatewayConfig target = new GatewayConfig(string.Empty);
            Assert.IsFalse(target.IsValid);
            Assert.IsTrue(target.DatabaseType == DatabaseType.SqlServer);

            target = new GatewayConfig(null);
            Assert.IsFalse(target.IsValid);
            Assert.IsTrue(target.DatabaseType == DatabaseType.SqlServer);

            target = new GatewayConfig("connectionString");
            Assert.IsTrue(target.IsValid);
            Assert.IsTrue(target.DatabaseType == DatabaseType.SqlServer);
        }

        /// <summary>
        ///GatewayConfig 构造函数 的测试
        ///</summary>
        [TestMethod()]
        public void GatewayConfigConstructorWithCommandTimeoutTest()
        {
            string connectionString ="xxxx"; 
            DatabaseType databaseType =DatabaseType.SqlServer; 
            int commandTimeout = 50; 

            GatewayConfig target = new GatewayConfig(connectionString, databaseType, commandTimeout);
            Assert.IsTrue(target.IsValid);
            Assert.IsTrue(target.CommandTimeout == commandTimeout);

            target.CommandTimeout = -1;
            Assert.IsTrue(target.CommandTimeout == GatewayConfig.DefaultCommandTimeout);

            target.CommandTimeout = 0;
            Assert.IsTrue(target.CommandTimeout == GatewayConfig.DefaultCommandTimeout);

            target = new GatewayConfig(connectionString, databaseType, -1);
            Assert.IsTrue(target.CommandTimeout == GatewayConfig.DefaultCommandTimeout);

            target = new GatewayConfig(connectionString, databaseType, 0);
            Assert.IsTrue(target.CommandTimeout == GatewayConfig.DefaultCommandTimeout);
        }

        /// <summary>
        ///GatewayConfig 构造函数 的测试
        ///</summary>
        [TestMethod()]
        public void GatewayConfigConstructorWithDatabaseTypeTest()
        {
            GatewayConfig target = new GatewayConfig(string.Empty, DatabaseType.SqlServer);
            Assert.IsFalse(target.IsValid);

            target = new GatewayConfig(null, DatabaseType.SqlServer);
            Assert.IsFalse(target.IsValid);

            target = new GatewayConfig("xxxx", DatabaseType.SqlServer);
            Assert.IsTrue(target.IsValid);
            Assert.IsTrue(target.DatabaseType == DatabaseType.SqlServer);

            target = new GatewayConfig("xxxx", DatabaseType.Oracle);
            Assert.IsTrue(target.DatabaseType == DatabaseType.Oracle);

            target = new GatewayConfig("xxxx", DatabaseType.Oledb);
            Assert.IsTrue(target.DatabaseType == DatabaseType.Oledb);
        }

        /// <summary>
      
    }
}
